import axios,{CancelToken} from "./config.js"
//请求登陆接口方法
export const loginApi = (username,password)=>axios.post("/api/users/login",{
    username,
    password
})
//获取验证码
export const getCaptchaApi = ()=>axios.get("/api/users/getCaptcha")
//校验验证码
export const verifyCaptcha = (captcha)=>axios.get("/api/users/verifyCaptcha",{
    params:{
        captcha
    }
})
//获取登陆日志,预留componentInstance是为了组件传this进来，再把c方法绑给组件，组件就可以通过this.cancelToken来使用中断请求方法
// export const getLoginLogApi = (componentInstance,page = 1,count = 5)=>axios.get("/getloginlog",{
export const getLoginLogApi = (page = 1,count = 15)=>axios.get("/api/getloginlog",{
    // cancelToken:new CancelToken((c)=>{
    //     //c这个方法可以绑给组件实例，调用此方法可以中断请求
    //     componentInstance.cancelToken = c
    // }),
    params:{
        page,
        count
    }
})
//获取微信二维码地址
export const getQrcodeUrlApi = (sid) => axios.get("/api/users/getQrcode", {
    params: {
      sid
    }
  })

//微信登陆
export const wechatLoginApi =(wechatCode)=>axios.get("/api/users/wechatLogin",{
    params:{
        wechatCode
    }
})
//获取权限菜单路由
export const getMenulisrApi =()=>axios.get("/api/permission/getMenuList")

//获取学员列表
export const getStuListApi =(page=1,count=10,classes="")=>axios.get("/api/students/getstulist",{
    params:{
        page,
        count,
        class:classes
    }
})
//增加学员条目api
export const addStuApi = data => axios.post("/api/students/addstu", data)
//编辑学员条目api
export const updateStuApi = data =>axios.post("/api/students/updatestu",data)
//删除学员条目api
export const deleteStuApi = data =>axios.get("/api/students/delstu",{
    params:{
        sId:data
    }
})
//选择班级
export const getSelectClassApi = () =>axios.get("/api/students/getclasses")
//搜索学员
export const searchStuApi = (page,key,count) =>{
    page=page||1
    key=key||""
    count=count||10
    return axios.get("/api/students/searchstu",{
    params:{
        page,
        count,
        key
    }
})}
//获取vip产品
//20210827165510715
export const getVipProductApi =(category_id="20210827165510715",product_id)=>axios.get("/api/product/get_product",{
    params:{
        category_id,
        product_id
    }
})

//获取订单,不传参获取全部订单
export const getOrderApi =(order_id	)=>axios.post("/api/order/get_order",{
    order_id
})
//删除订单
export const delOrderApi = (order_id)=>axios.get("/api/order/del_order",{
    params:{
        order_id
    }
})

//生成支付订单  
export const createPreOrderApi =(product_id,quantity=1)=>axios.post("/api/order/pre_order",{
    product_id,
    quantity
})
//发起支付 
export const goPayingApi =(order_id)=>axios.post("/api/pay/payment",{
    order_id
})
//ajax轮询查询支付结果
export const checkOrderResultApi = (order_id)=>axios.get("/api/order/query_order_status",{
    params:{
        order_id
    }
})
//添加用户
export const addUserApi =(username,password,phone,nickname)=>axios.post("/api/users/addUser",{
    username,
    password,
    phone,
    nickname
})
//修改用户信息
export const updateUserApi =(unid,username,password,phone,nickname,roleid=200,vipLevel,headimgurl,sex,city,province,country)=>axios.post("/api/users/updateUser",{
    unid,
    username,
    password,
    phone,
    nickname,
    roleid,
    vipLevel,
    headimgurl,
    sex,
    city,
    province,
    country
})
//更改自己账户的头像  我的中心添加功能  
//请求地址 /users/uploadAvatar 传递当前账户的unid 和 headimgurl
//调用的时候服务器地址的端口号改为:443 不要用80 不然会报502
export const updateUserAvatar = (headimgurl,unid)=>axios.post("/api/users/uploadAvatar",{
    headimgurl,
    unid
})

//获取手机验证码
export const getPhoneloginYZApi =(phoneNumber)=>axios.post("/api/sms/send",{
    phoneNumber,
})
//手机短信验证登陆  传5位验证码
export const phoneloginApi =(code)=>axios.post("/api/users/login?type=sms",{
    code,
})
//获取所有用户列表
export const getAllUsers =()=>axios.get("/api/users/getAllUsers")
//请求天气
export const getWeather =(key="",city)=>axios.get("/api/weather/getWeather",{
    params:{
        key,
        city
    }
})

//获取任务数据
export const getTarskData =()=>axios.get("/data/tarsk.json")
//期望课程数据
export const expectDataApi = () => axios.get("/data/expect.json");
//折线图数据
export const lineDataApi = () => axios.get("/data/rate.json");